from flask import Flask,request
from flask import render_template
# 调用自定义模块中的函数


# Flask:中央登记中心
app = Flask(__name__)

# 【Flask】(https://dormousehole.readthedocs.io/en/latest/quickstart.html#id10)
# 【HTMl】(https://www.w3school.com.cn/html/index.asp)
# 【jinja2】(https://palletsprojects.com/p/jinja/)

# 1. 路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
# 1.1 url: 相对于：http://127.0.0.1：5000的相对路径
# 1.2 methods:【GET】【POST】
# 2. 视图函数：
# 2.1 函数过程决定了你操作的方法（实现的功能），例如 if elif else for while ...
# 2.2 return：返回数据内容，text文本，HTML文件（模板渲染），JSON文件等

# 【GET】
@app.route('/',methods=['GET'])
def hello_world():
    return render_template('hello.html')

@app.route('/index',methods=['GET'])
def index():
    return render_template('index.html')

@app.route('/result', methods=['POST', 'GET'])
def result_name():
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    full_name = firstname.title() + ' ' + lastname.title()
    return render_template("result.html", name=full_name)

@app.route('/abc', methods=['POST', 'GET'])
def abc():
    return render_template("abc.html")

@app.route('/words', methods=['POST', 'GET'])
def result_word():
    word = request.form.get("word")
    vowels = request.form.get("vowels")
    found = {}
    for i in word:
        if i in vowels:
            found.setdefault(i, 0)
            found[i] += 1
    for j in found:
        k = j
        v = found[j]

    return render_template("abc_result.html",
                           key=k,
                           value=v
                           )

@app.route('/login', methods=['POST', 'GET'])
def login():
    return render_template("login.html")

@app.route('/buy',methods=['GET','POST'])
def shoppingcart():
    return render_template('buy.html')

@app.route('/chonggong',methods=['GET','POST'])
def checkout():
    return render_template('chonggong.html')









if __name__ == '__main__':
    app.run(host='127.0.0.1',port=5000,debug=True)


